<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		<style type="text/css">
			table{
				border-collapse: collapse;
			}
		</style>
	</head>
	<body>
		<form>
			<table border="1" width="300px" height="30px" id="myTable" >
				<tr>
					<td height="30px"></td>
					<td></td>
					<td></td>
					<td></td>
				</tr>
			</table>
			<input type="button" value="添加一行" onclick="add()" />
			<input type="button" value="删除最后行" onclick="del()" />
		</form>
		<script type="text/javascript">
			function add(){
				var table=document.getElementById("myTable");
				var tr=document.createElement("tr");
				for (var i = 1; i < 5; i++) {
					var td=document.createElement("td");
					td.style.height="30px";
					tr.appendChild(td);
				}
				table.appendChild(tr);
			}
			function del(){
				var table=document.getElementById("myTable");
				var tr=table.lastChild;
				var td=table.childNodes;
				if (table.rows.length==1) {
					alert("最后一行不可删除");
				} else{
					table.removeChild(tr);
				}
				
			}
		</script>
	</body>
</html>
